﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Threading;
using HtmlAgilityPack;
namespace Search
{

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        void ThreadA()
        {
         
            
                HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc = web.Load("https://cn.bing.com/search?q=" + tbSearch1.Text);
                HtmlNode Node = doc.DocumentNode.SelectSingleNode("//*[@id='b_results']");
                HtmlNodeCollection nodes = Node.ChildNodes;
                foreach (var node in nodes)
                {
                    foreach(char ch in node.InnerText)
                    {
                        if (ch > 32&&tb1.Text.Length <= 200)
                        {
                            tb1.Text += ch.ToString();
                        }
                        else if(tb1.Text.Length>200)
                        {
                           
                            return;
                        }
                    }

                }

            
        }
        void ThreadB()
        {
      
                HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc = web.Load("https://cn.bing.com/search?q=" + tbSearch2.Text);
                HtmlNode Node = doc.DocumentNode.SelectSingleNode("//*[@id='b_results']");
                HtmlNodeCollection nodes = Node.ChildNodes;
                foreach (var node in nodes)
                {
                    foreach (char ch in node.InnerText)
                    {
                        if (ch > 32  && tb2.Text.Length <= 200)
                        {
                            tb2.Text += ch.ToString();
                        }
                        else if(tb2.Text.Length > 200)
                        {
                          
                            return;
                        }
                    }

                }
            
        }
        private void btSearch_Click(object sender, EventArgs e)
        {
            try
            {
                new Thread(ThreadA).Start();
                new Thread(ThreadB).Start();
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
    }
}
